package com.zkj.response;

import java.io.IOException;
import java.util.Random;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 定时刷新
 * 
 * @author zkj
 * 
 */
public class Servlet_Resp_Demo2 extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		/**
		 * 跳转到其他页面
		 */
		// Refresh: 1;url=http://www.it315.org指示客户端刷新频率。单位是秒
		resp.setCharacterEncoding("utf-8");
		resp.setContentType("text/html;charset=utf-8");
		// resp.setHeader("Refresh", "4;URL=/zkjTest/index.jsp");
		 resp.setHeader("Refresh", "4;URL=http://www.baidu.com");
		resp.getWriter().write("登录成功,即将跳转~");

		/**
		 * 定时刷新本页面
		 * 
		 */
		// Random r = new Random();
		// resp.setCharacterEncoding("utf-8");
		// resp.setContentType("text/html;charset=utf-8");
		// resp.setIntHeader("Refresh", 2);// 时间单位：秒
		// resp.getWriter().write("一直刷新本页面");
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		doGet(req, resp);

	}

}
